/**
 * DrawCanvas.java
 *
 * Provider: CoderDream's Studio
 *
 * History
 *	Date(DD/MM/YYYY)    Author          Description
 * ----------------------------------------------------------------------------
 *	Nov 5, 2007		CoderDream		Created
 */
package com.coderdream.chapter22.command.sample.drawer;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;

import com.coderdream.chapter22.command.sample.command.MacroCommand;

/**
 * <pre>
 * DrawCanvas.java
 * </pre>
 * 
 */
public class DrawCanvas extends Canvas implements Drawable {
	// Config color
	private Color color = Color.red;
	// Draw Point's radius
	private int radius = 6;
	// Record
	private MacroCommand history;

	/**
	 * @param width
	 * @param height
	 * @param history
	 */
	public DrawCanvas(int width, int height, MacroCommand history) {
		setSize(width, height);
		setBackground(Color.white);
		this.history = history;
	}

	/**
	 * Draw total record
	 */
	public void paint(Graphics g) {
		history.execute();
	}

	/* (non-Javadoc)
	 * @see com.coderdream.chapter22.command.sample.drawer.Drawable#draw(int, int)
	 */
	public void draw(int x, int y) {
		Graphics g = getGraphics();
		g.setColor(color);
		g.fillOval(x - radius, y - radius, radius * 2, radius * 2);
	}

}
